package com.ihr360.payroll.model.dto.reference;

import com.ihr360.commons.entityhandler.DateHandler;
import com.ihr360.commons.model.entity.NumberIdWithTime;
import com.ihr360.payroll.entity.salary.AppliedToWrappers;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import java.util.List;

/**
 * 引用的服务内的可提供的实体定义
 */
@EntityListeners(DateHandler.class)
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReferenceService extends NumberIdWithTime<Long> {
    /**
     * 引用所属的对象
     */
    @Column(length = 40, unique = true)
    private String refId;

    /**
     * 引用所属的对象显示名称
     */
    @Column(length = 40)
    private String refName;

    /**
     * 服务访问路径
     */
    @Column(length = 40)
    private String path;

    @ManyToOne
    @JoinColumn
    private ReferenceApplication refApplication;

    @OneToMany(mappedBy = "refService", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<ReferenceProperty> properties;

    @Column(columnDefinition = "text")
    @Type(type = "json")
    private AppliedToWrappers applies;

    public String getRefId() {
        return refId;
    }

    public void setRefId(String refId) {
        this.refId = refId;
    }

    public String getRefName() {
        return refName;
    }

    public void setRefName(String refName) {
        this.refName = refName;
    }

    public ReferenceApplication getRefApplication() {
        return refApplication;
    }

    public void setRefApplication(ReferenceApplication refApplication) {
        this.refApplication = refApplication;
    }

    public List<ReferenceProperty> getProperties() {
        return properties;
    }

    public void setProperties(List<ReferenceProperty> properties) {
        this.properties = properties;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public AppliedToWrappers getApplies() {
        return applies;
    }

    public void setApplies(AppliedToWrappers applies) {
        this.applies = applies;
    }
}
